package com.zking.web.ly;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zking.dao.domain.Information;
import com.zking.service.ly.Iindex04Service;

@Controller

public class Index04Controller {
	@Autowired
	Iindex04Service is;

	@RequestMapping(value = "/queryly")
	public ModelAndView query(Integer information_id, HttpServletRequest request) {
		System.out.println("information_id:"+information_id);
		ModelAndView modelAndView = new ModelAndView();
		Information ifm = is.query(information_id);
		System.out.println(ifm);
		if (ifm != null) {
			System.out.println("进来了");
			request.getSession().setAttribute("ifm", ifm);
			modelAndView.addObject("ifm", ifm);
			modelAndView.setViewName("index04");
		} else {
			request.setAttribute("msg", "没查询到数据！");
			modelAndView.setViewName("index04");
		}
		return modelAndView;
	}

	@RequestMapping(value = "/updately")
	public ModelAndView update(Integer id, HttpServletRequest request,@ModelAttribute Information information) {
		System.out.println("id="+id);
		ModelAndView modelAndView = new ModelAndView("redirect:/queryly?id="+id);
		Information ifm2 = is.query(id);
		System.out.println("修改之前："+ifm2);
		if (ifm2 != null) {
			System.out.println("进来了");
//			ifm2.setCom_logo(information.getCom_logo());
			ifm2.setCom_abbreviation(information.getCom_abbreviation());
			ifm2.setAdvantage(information.getAdvantage());
//			ifm2.setCom_poster(information.getCom_poster());
//			ifm2.setProduct_name(information.getProduct_name());
//			ifm2.setProduct_address(information.getProduct_address());
//			ifm2.setProduct_brief(information.getProduct_brief());
//			ifm2.setCom_introduction(information.getCom_introduction());
//			System.out.println(information.getAdvantage());
			int i = is.update(ifm2);
			System.out.println(i);
			modelAndView.addObject("ifm", i);
			System.out.println("修改后："+ifm2);
			return modelAndView;
		} else {
			System.out.println("修改失败！");
		}
		return modelAndView;
	}
	@RequestMapping(value = "/updately2")
	public ModelAndView update2(Integer id, HttpServletRequest request,@ModelAttribute Information information) {
		System.out.println("id="+id);
		ModelAndView modelAndView = new ModelAndView("redirect:/queryly?id="+id);
		Information ifm2 = is.query(id);
		System.out.println("修改之前："+ifm2);
		if (ifm2 != null) {
			ifm2.setProduct_name(information.getProduct_name());
			ifm2.setProduct_address(information.getProduct_address());
			ifm2.setProduct_brief(information.getProduct_brief());
			int i2 = is.update(ifm2);
			modelAndView.addObject("ifm", i2);
			System.out.println("修改后："+ifm2);
			return modelAndView;
		} else {
			System.out.println("修改失败！");
		}
		return modelAndView;
	}
	@RequestMapping(value = "/updately3")
	public ModelAndView update3(Integer id, HttpServletRequest request,@ModelAttribute Information information) {
		System.out.println("id="+id);
		ModelAndView modelAndView = new ModelAndView("redirect:/queryly?id="+id);
		Information ifm2 = is.query(id);
		System.out.println("修改之前："+ifm2);
		if (ifm2 != null) {
			ifm2.setCom_introduction(information.getCom_introduction());
			int i3 = is.update(ifm2);
			modelAndView.addObject("ifm", i3);
			System.out.println("修改后："+ifm2);
			return modelAndView;
		} else {
			System.out.println("修改失败！");
		}
		return modelAndView;
	}
	@RequestMapping(value = "/updately4")
	public ModelAndView update4(Integer id, HttpServletRequest request,@ModelAttribute Information information) {
		System.out.println("id="+id);
		ModelAndView modelAndView = new ModelAndView("redirect:/queryly?id="+id);
		Information ifm2 = is.query(id);
		System.out.println("修改之前："+ifm2);
		if (ifm2 != null) {
			ifm2.setCom_city(information.getCom_city());
			ifm2.setCom_size(information.getCom_size());
			ifm2.setCom_website(information.getCom_website());
			int i4 = is.update(ifm2);
			modelAndView.addObject("ifm", i4);
			System.out.println("修改后："+ifm2);
			return modelAndView;
		} else {
			System.out.println("修改失败！");
		}
		return modelAndView;
	}
	@RequestMapping(value = "/updately5")
	public ModelAndView update5(Integer id, HttpServletRequest request,@ModelAttribute Information information) {
		System.out.println("id="+id);
		ModelAndView modelAndView = new ModelAndView("redirect:/queryly?id="+id);
		Information ifm2 = is.query(id);
		System.out.println("修改之前："+ifm2);
		if (ifm2 != null) {
			ifm2.setCom_development(information.getCom_development());
			ifm2.setCom_investment(information.getCom_investment());
			int i5 = is.update(ifm2);
			modelAndView.addObject("ifm", i5);
			System.out.println("修改后："+ifm2);
			return modelAndView;
		} else {
			System.out.println("修改失败！");
		}
		return modelAndView;
	}
	@RequestMapping(value = "/updately6")
	public ModelAndView update6(Integer id, HttpServletRequest request,@ModelAttribute Information information) {
		System.out.println("id="+id);
		ModelAndView modelAndView = new ModelAndView("redirect:/queryly?id="+id);
		Information ifm2 = is.query(id);
		System.out.println("修改之前："+ifm2);
		if (ifm2 != null) {
			ifm2.setCom_boss(information.getCom_boss());
			ifm2.setCom_position(information.getCom_position());
			ifm2.setCom_weibo(information.getCom_weibo());
			ifm2.setCom_founder(information.getCom_founder());
			int i6 = is.update(ifm2);
			modelAndView.addObject("ifm", i6);
			System.out.println("修改后："+ifm2);
			return modelAndView;
		} else {
			System.out.println("修改失败！");
		}
		return modelAndView;
	}
}
